#ifndef __ADPM_TOOLS_H__
#define __ADPM_TOOLS_H__

#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/time.h>
#include <linux/slab.h>
#include <linux/ctype.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/module.h>
#include <linux/parser.h>
#include <linux/kernel.h>
#include <linux/seq_file.h>
#include <linux/backing-dev.h>
#include <linux/atomic.h>
#include <linux/rbtree.h>
#include <linux/hashtable.h>
#include <linux/types.h>
#include "types.h"



#define ADPM_DEBUG 1

#if ADPM_DEBUG
#define adpm_pr(fmt, ...) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#else
#define adpm_pr(fmt, ...) ((void)(0))
#endif


extern struct adpm_page *adpm_map;

static inline unsigned long adpm_page_to_pfn(struct adpm_page *pg){
  return (unsigned long)(pg - adpm_map);
}
static inline unsigned long adpm_page_to_real_pfn(struct adpm_page *pg, struct adpm_sb_info *sbi)
{
  return adpm_page_to_pfn(pg) + (unsigned long)(sbi->phys_addr >> PAGE_SHIFT);
}
static inline void *adpm_page_to_vir_addr(struct adpm_page *pg, struct adpm_sb_info *sbi){
  return (void*)((char *)(sbi->virt_addr) + (adpm_page_to_pfn(pg)<<PAGE_SHIFT));
}

static inline void adpm_page_set_stat(struct adpm_page* p, int st)
{
  if(!p)return ;
  p->flag &= ~ADPM_PAGE_STAT_MASK;
  p->flag |= st;
}
static inline unsigned long adpm_page_get_stat(struct adpm_page *p)
{
  return p->flag & ADPM_PAGE_STAT_MASK;
}

static inline bool adpm_get_swap_flag(struct adpm_page *p)
{
  return !!(p->flag & ADPM_PAGE_SWAP_FLAG);
}
static inline void adpm_set_swap_flag(struct adpm_page *p)
{
  p->flag |= ADPM_PAGE_SWAP_FLAG;
}
static inline void adpm_clr_swap_flag(struct adpm_page *p)
{
  p->flag &= ~ADPM_PAGE_SWAP_FLAG;
}


#endif
